﻿using System;
using SmartHRMS.Presentation.Company;
using System.IO;

namespace SmartHRMS.UI.Web.Modules.Administration.Company
{
    public partial class CompanyDetail : System.Web.UI.UserControl, ICompanyView
    {
        private CompanyPresenter _Presenter;
        protected string UploadFolderPath = "~/Content/Uploads/";
        public static byte[] imageToUpload;

        protected void Page_Init(object sender, EventArgs e)
        {
            _Presenter = new CompanyPresenter(this);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _Presenter.Display();

            }
        }

        public void ErrorMessage(string Message)
        {
            if (String.IsNullOrEmpty(Message))
            {
                pnlError.Visible = false;
            }
            else
            {
                pnlError.Visible = true;
            }
            this.litErrorMessage.Text = Message + "<br/>";
        }

        public void InfoMessage(string Message)
        {
            if (String.IsNullOrEmpty(Message))
            {
                pnlInfo.Visible = false;
            }
            else
            {
                pnlInfo.Visible = true;
            }
            this.litInfoMessage.Text = Message + "<br/>";
        }

        public void WarringMessage(string Message)
        {
            if (String.IsNullOrEmpty(Message))
            {
                pnlWarr.Visible = false;
            }
            else
            {
                pnlWarr.Visible = true;
            }
            this.litWarrMessage.Text = Message + "<br/>";
        }

        public void ViewTitle(string title)
        {
            //throw new NotImplementedException();
        }

        #region ICompanyView Members

        public Guid CompanyId
        {
            get
            {
                return Guid.Empty;
            }
        }

        public string CompanyName
        {
            get
            {
                return txtCompanyName.Text;
            }
            set
            {
                txtCompanyName.Text = value;
            }
        }

        public string EstablishDate
        {
            get
            {
                return txtEstablishDate.Text;
            }
            set
            {
                txtEstablishDate.Text = value;
            }
        }

        public string Mission
        {
            get
            {
                return txtMission.Text;
            }
            set
            {
                txtMission.Text = value;
            }
        }

        public string Vision
        {
            get
            {
                return txtVision.Text;
            }
            set
            {
                txtVision.Text = value;
            }
        }

        public string Slogan
        {
            get
            {
                return txtSlogan.Text;
            }
            set
            {
                txtSlogan.Text = value;
            }
        }

        public byte[] Logo
        {
            get
            {
                return imageToUpload; 
            }
            set
            {
                imageToUpload = value;
            }
        }

        public string SaveButtonText
        {
            set
            {
                this.btnSaveTop.Text = value;
            }
        }

        public string Country
        {
            get
            {
                return txtCountry.Text;
            }
            set
            {
                txtCountry.Text = value;
            }
        }

        public string Street
        {
            get
            {
                return txtStreet.Text;
            }
            set
            {
                txtStreet.Text = value;
            }
        }


        public string HouseNumber
        {
            get
            {
                return txtHouseNumber.Text;
            }
            set
            {
                txtHouseNumber.Text = value;
            }
        }


        public string City
        {
            get
            {
                return txtCity.Text;
            }
            set
            {
                txtCity.Text = value;
            }
        }

        public string State
        {
            get
            {
                return txtState.Text;
            }
            set
            {
                txtState.Text = value;
            }
        }

        public string PostCode
        {
            get
            {
                return txtPostCode.Text;
            }
            set
            {
                txtPostCode.Text = value;
            }
        }

        public string CellPhone
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string HomePhone
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string OfficePhone
        {
            get
            {
                return txtOfficePhone.Text;
            }
            set
            {
                txtOfficePhone.Text = value;
            }
        }

        public string Fax
        {
            get
            {
                return txtFax.Text;
            }
            set
            {
                txtFax.Text = value;
            }
        }

        public string Email
        {
            get
            {
                return txtEmail.Text;
            }
            set
            {
                txtEmail.Text = value;
            }
        }

        public string Website
        {
            get
            {
                return txtWebsite.Text;
            }
            set
            {
                txtWebsite.Text = value;
            }
        }

        #endregion

        protected void btnSaveTop_Click(object sender, EventArgs e)
        {
            _Presenter.SaveCompanyInformation();          
        }

        public bool ThumbnailCallback()
        {
            return false;
        }

        protected void FileUploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
            AsyncFileUpload1.SaveAs(Server.MapPath(this.UploadFolderPath) + filename);
            imageToUpload = new byte[AsyncFileUpload1.PostedFile.ContentLength];
            using (Stream stream = AsyncFileUpload1.PostedFile.InputStream)
            {
                stream.Read(imageToUpload, 0, imageToUpload.Length);
            }

        }
    }
}